Skip to content

Macros - #10

Open
szymon-zadworny wants to merge 16 commits into
oneapi-src:mainfrom
szymon-zadworny:macros
Open

Macros#10
szymon-zadworny wants to merge 16 commits into
oneapi-src:mainfrom
szymon-zadworny:macros

Conversation

@szymon-zadworny

Copy link
Copy Markdown
Contributor

This PR adds:

  • A new derive macro that simplifies implementing the KernelArgumentList trait
  • A new proc-macro that implements KernelArgumentList for tuples up to 16 arguments in size
  • A derive macro example.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces proc-macros to reduce boilerplate when supplying kernel argument lists, adding both a derive macro for structs and generated KernelArgumentList impls for tuples (up to 16 args), and updates examples to demonstrate the new ergonomics.

Changes:

  • Add #[derive(KernelArgumentList)] and a tuple-impl generator proc-macro in the new oneapi-rs-derive crate.
  • Extend oneapi-rs kernel argument support (single-arg list blanket impl; KernelArgument for &Buffer/&mut Buffer).
  • Update/add examples to use tuple args and the new derive macro.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
oneapi-rs/src/kernel.rs Adds KernelArgumentList<1> blanket impl and wires in derive + tuple macro expansion.
oneapi-rs/src/buffer.rs Refactors raw-arg serialization and adds KernelArgument impls for &Buffer/&mut Buffer.
oneapi-rs/examples/kernel_launch.rs Simplifies example to pass args as a tuple (and switches to f64/double).
oneapi-rs/examples/kernel_launch_derive.rs New example demonstrating #[derive(KernelArgumentList)].
oneapi-rs/Cargo.toml Adds oneapi-rs-derive dependency.
oneapi-rs-derive/src/lib.rs Implements derive macro and tuple-impl generator proc-macro.
oneapi-rs-derive/Cargo.toml Declares new proc-macro crate and dependencies.
Cargo.toml Adds oneapi-rs-derive to the workspace.
Cargo.lock Locks new dependencies (including oneapi-rs-derive and syn v3).
Comments suppressed due to low confidence (2)

oneapi-rs-derive/src/lib.rs:30

  • To make the expansion more robust (avoids relying on method-resolution details and reduces the chance of conflicts with other as_raw_arg methods), prefer calling the trait method with a fully-qualified path.
            unsafe fn as_raw_arg_list(&self) -> [&[u8]; #argc] {
                [ #(unsafe { self.#members.as_raw_arg() }),* ]
            }

oneapi-rs-derive/src/lib.rs:61

  • This doc comment also references KernelArgumentList<T>, but the trait uses a const generic (KernelArgumentList<const ARGC: usize>).
/// A macro that generates tuples from 2..N which implement the `KernelArgumentList<T>` trait.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread oneapi-rs/src/buffer.rs
Comment thread oneapi-rs-derive/src/lib.rs Outdated
Comment thread oneapi-rs-derive/src/lib.rs Outdated
Comment thread oneapi-rs-derive/src/lib.rs
Comment thread oneapi-rs/examples/kernel_launch_derive.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (2)

oneapi-rs-derive/src/lib.rs:77

  • impl_arg_list_for_tuples uses unwrap() when parsing the arity. If the macro is invoked with invalid input, it will panic rather than producing a structured compile error at the call site.
pub fn impl_arg_list_for_tuples(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as LitInt);
    let argc = input.base10_parse::<usize>().unwrap();

    let impls = { 2..=argc }.map(get_single_tuple_impl);

oneapi-rs/examples/kernel_launch_derive.rs:15

  • KernelArgument is imported but not used in this example; removing it avoids unused_imports warnings (which can become build failures under -D warnings).
use oneapi_rs::{
    buffer::Buffer,
    kernel::{KernelArgument, KernelArgumentList},
    queue::Queue,
    range::NdRange,
    usm::{SharedAllocator, UsmAllocator},
};

Comment thread oneapi-rs/src/kernel.rs
Comment thread oneapi-rs/src/kernel.rs
Comment thread oneapi-rs-derive/src/lib.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants